<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目简称">
              <a-input placeholder="请输入项目简称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="风险编号">
              <a-input placeholder="请输入风险编号" v-model="queryParam.riskCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="风险类型">
              <j-dict-select-tag placeholder="请选择风险类型" v-model="queryParam.riskType" dictCode="risk_type"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="风险状态">
                <j-dict-select-tag placeholder="请选择风险状态" v-model="queryParam.riskState" dictCode="icm_pm_projectRisks"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('风险总览')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot='taskDes' slot-scope='text'>
          <j-ellipsis :value='text' :length='10' />
        </template>
        <template slot="projectName" slot-scope="text, record">
          <a @click="handleDetail(record)">{{text}}</a>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="confimor(record)">确认</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a style="color:red">删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <hf-pm-project-risks-modal ref="modalForm" @ok="modalFormOk"></hf-pm-project-risks-modal>
    <pm-project-risks-modal-detail ref="pmProjectRisksModalDetail"></pm-project-risks-modal-detail>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HfPmProjectRisksModal from './modules/HfPmProjectRisksModal'
  import { getAction } from '@api/manage'
  import PmProjectRisksModalDetail from '@views/hifar/pm/modules/PmProjectRisksModalDetail'

  export default {
    name: 'HfPmProjectRisksList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      HfPmProjectRisksModal,
      PmProjectRisksModalDetail
    },
    data () {
      return {
        description: '风险总览管理页面',
        // 表头
        columns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'风险编号',
            align:"center",
            dataIndex: 'riskCode',
            scopedSlots: { customRender: 'projectName' }
          },
          {
            title:'项目简称',
            align:"center",
            dataIndex: 'projectName',
            scopedSlots: { customRender: 'taskDes' }
          },
          {
            title: '专题名称',
            align: "center",
            dataIndex: 'subjectName',
            scopedSlots: { customRender: 'taskDes' }
          },
          {
            title:'风险类型',
            align:"center",
            dataIndex: 'riskType_dictText'
          },
          {
            title:'风险等级',
            align:"center",
            dataIndex: 'riskGrade_dictText'
          },
          {
            title:'风险描述',
            align:"center",
            dataIndex: 'riskDes',
            scopedSlots: { customRender: 'taskDes' }
          },
          {
            title:'影响分析',
            align:"center",
            dataIndex: 'affect',
            scopedSlots: { customRender: 'taskDes' }
          },
          {
            title:'应对措施',
            align:"center",
            dataIndex: 'solutions',
            scopedSlots: { customRender: 'taskDes' }
          },
          {
            title:'风险负责人',
            align:"center",
            dataIndex: 'dutyPersion'
          },
          {
            title:'确认人',
            align:"center",
            dataIndex: 'confirmorName'
          },
          {
            title: '确认时间',
            align: 'center',
            dataIndex: 'confirmorTime'
          }
          // {
          //   title: '操作',
          //   dataIndex: 'action',
          //   align:"center",
          //   fixed:"right",
          //   width:147,
          //   scopedSlots: { customRender: 'action' }
          // }
        ],
        url: {
          list: "/pm/hfPmProjectRisks/list",
          delete: "/pm/hfPmProjectRisks/delete",
          deleteBatch: "/pm/hfPmProjectRisks/deleteBatch",
          exportXlsUrl: "/pm/hfPmProjectRisks/exportXls",
          importExcelUrl: "pm/hfPmProjectRisks/importExcel",
          confim: 'pm/hfPmProjectRisks/confim'
        },
        dictOptions:{},
        superFieldList:[],
        queryModel: true
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'createBy',text:'创建人',dictCode:''})
        fieldList.push({type:'date',value:'createTime',text:'创建时间'})
        fieldList.push({type:'string',value:'deleteFlag',text:'删除标记',dictCode:''})
        fieldList.push({type:'Text',value:'remarks',text:'备注',dictCode:''})
        fieldList.push({type:'string',value:'riskCode',text:'风险编号',dictCode:''})
        fieldList.push({type:'string',value:'projectId',text:'项目id',dictCode:''})
        fieldList.push({type:'string',value:'riskType',text:'风险类型（字典：存在、发生、关闭）',dictCode:'icm_pm_projectRisks'})
        fieldList.push({type:'string',value:'riskGrade',text:'风险等级',dictCode:''})
        fieldList.push({type:'string',value:'riskDes',text:'风险描述',dictCode:''})
        fieldList.push({type:'Text',value:'affect',text:'影响分析',dictCode:''})
        fieldList.push({type:'string',value:'solutions',text:'应对措施',dictCode:''})
        fieldList.push({type:'string',value:'dutyPersion',text:'风险负责人',dictCode:''})
        fieldList.push({type:'string',value:'confirmorId',text:'确认人id',dictCode:''})
        fieldList.push({type:'Text',value:'confirmorDes',text:'确认意见',dictCode:''})
        this.superFieldList = fieldList
      },
      confimor(record) {
        if (record.confirmorName != null) {
          this.$message.error('此风险已确认，请勿重复确认!');
          return;
        }
        var obj = this.$ls.storage.pro__Login_Username;
        var jsonObj = JSON.parse(obj);
        record.confirmorName = jsonObj.value;
        getAction(this.url.confim, record).then((res) => {
          if (res.success) {
            this.loadData()
            this.$message.success("操作完成。")
          } else {
            this.$message.warning("操作失败！")
          }
        })
      },
      handleEdit: function (record) {
        if (record.confirmorName != null) {
          this.$message.error('此风险已确认，禁止编辑!');
          return;
        }
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.title = "编辑";
        this.$refs.modalForm.disableSubmit = false;
      },
      handleDetail: function(record) {
        record.clickArchive = false //为了识别是点击了编辑或详情
        this.$refs.pmProjectRisksModalDetail.edit(record)
        this.$refs.pmProjectRisksModalDetail.title = '详情'
        this.$refs.pmProjectRisksModalDetail.disableSubmit = true
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>